package cn.uway.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;

import cn.uway.filter.DemoFilter;

@Configuration
public class FilterConfig {

	 @Bean
	 public FilterRegistrationBean  encodingFilter() {
		 FilterRegistrationBean  registrationBean = new FilterRegistrationBean();
		 registrationBean.setName("encodingFilter");
		 CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
		 registrationBean.setFilter(encodingFilter);
		 registrationBean.setOrder(1);
		 registrationBean.setAsyncSupported(true); //支持异步请求
		 Map<String,String> initParameters = new HashMap<String,String>();
		 initParameters.put("encoding", "UTF-8");
		 registrationBean.setInitParameters(initParameters);
		 List<String> urlList = new ArrayList<String>();
		 urlList.add("/*");
		 registrationBean.setUrlPatterns(urlList);
		 return registrationBean;
	 }
	 
	 //@Bean
	 public FilterRegistrationBean  demoFilter() {
		 FilterRegistrationBean  registrationBean = new FilterRegistrationBean();
		 registrationBean.setName("demoFilter");
		 DemoFilter demoFilter = new DemoFilter();
		 registrationBean.setFilter(demoFilter);
		 registrationBean.setOrder(1);
		 registrationBean.setAsyncSupported(true); //支持异步请求
		// Map<String,String> initParameters = new HashMap<String,String>();
		// initParameters.put("encoding", "UTF-8");
		//registrationBean.setInitParameters(initParameters);
		 List<String> urlList = new ArrayList<String>();
		 urlList.add("/*");
		 registrationBean.setUrlPatterns(urlList);
		 return registrationBean;
	 }

}
